package de.tudarmstadt.ukp.muip.fibqdojo.rule.composite;

import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQMatchMode;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQRule;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQSentence;
import de.tudarmstadt.ukp.muip.fibqdojo.interfaces.IFIBQSentenceToken;
import de.tudarmstadt.ukp.muip.fibqdojo.rule.FormMatchingRule;
import de.tudarmstadt.ukp.muip.fibqdojo.rule.PartOfSpeechMatchingRule;
import de.tudarmstadt.ukp.muip.fibqdojo.util.FIBQUtil;

/**
 * Returns <code>true</code> as soon a token is found conforming the specified
 * form and part of speech tag.
 * 
 * @author Tobias Horsmann
 */
public class FormPosCompositeMatchingRule implements IFIBQRule {

    private FormMatchingRule formMatchingRule;
    private PartOfSpeechMatchingRule partOfSpeechMatchingRule;

    public FormPosCompositeMatchingRule(String form, String pos, IFIBQMatchMode matchMode) {
        formMatchingRule = new FormMatchingRule(form);
        partOfSpeechMatchingRule = new PartOfSpeechMatchingRule(pos, matchMode);
    }

    @Override
    public boolean match(IFIBQSentence sentence) {
        for (IFIBQSentenceToken sentenceToken : FIBQUtil.getSentenceToken(sentence)) {
            boolean match = match(sentenceToken);
            if (match) {
                return true;
            }
        }
        return false;
    }

    @Override
    public boolean match(IFIBQSentenceToken sentenceToken) {
        return formMatchingRule.match(sentenceToken) && partOfSpeechMatchingRule.match(sentenceToken);
    }

}
